//
//  EPAlertViewController.swift
//  EPHome
//
//  Created by liujianlong on 2022/8/15.
//

import UIKit

class EPAlertViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }
    
    ///必须要加上这个方法，否则self.modalPresentationStyle = .overFullScreen不生效
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        self.view.layoutIfNeeded()
        self.modalPresentationStyle = .overFullScreen
        self.view.backgroundColor = "#000000".color(0.6)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initUI(){}
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        let view = self.firstResponder(self.view)
        if view != nil{
            super.touchesEnded(touches, with: event)
            self.view.endEditing(true)
        } else{
            let touch = (touches as NSSet).allObjects.last as! UITouch
            if touch.view!.isDescendant(of: self.view.subviews.first ?? UIView()) == false
            {
                self.dismiss(animated:false, completion: nil)
            }
        }
    }
    
}
